package com.jblog.article.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * 类别
 * 
 * @author Bing
 * @time 2015.08.17
 */
@Entity
@Table(name = "category")
public class Category implements Serializable{

	private static final long serialVersionUID = -8318123053854203972L;

	private String id;

	/** 分类名称 */
	private String name;
	/** 序号 */
	private Integer seqNum;
	/** 状态 */
	private Integer status;
	/** 父分类 */
	private Category parent;

	private List<Article> articles;

	public Category() {
	}
	
	public Category(String id) {
		this.id = id;
	}

	public Category(String id, String name, Integer seqNum, Integer status) {
		this.id = id;
		this.name = name;
		this.seqNum = seqNum;
		this.status = status;
	}
	
	public Category(String id, String name, Integer seqNum, Integer status, Category parent) {
		this.id = id;
		this.name = name;
		this.seqNum = seqNum;
		this.status = status;
		this.parent = parent;
	}

	public Category(String id, String name, Integer seqNum, Integer status,
			Category parent, List<Article> articles) {
		this.id = id;
		this.name = name;
		this.seqNum = seqNum;
		this.status = status;
		this.parent = parent;
		this.articles = articles;
	}

	@Id
	@Column(name = "id", unique = true, nullable = false, length = 32)
	public String getId() {
		return id;
	}

	@Column(name = "name", nullable = false, length = 32)
	public String getName() {
		return name;
	}

	@Column(name = "seq_num")
	public Integer getSeqNum() {
		return seqNum;
	}

	@Column(name = "status")
	public Integer getStatus() {
		return status;
	}

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "pid")
	public Category getParent() {
		return parent;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY ,mappedBy="category")
	public List<Article> getArticles() {
		return articles;
	}

	public void setSeqNum(Integer seqNum) {
		this.seqNum = seqNum;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public void setArticles(List<Article> articles) {
		this.articles = articles;
	}

	public void setParent(Category parent) {
		this.parent = parent;
	}

}
